package com.nf.db;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Map;

/**
 * 用来把数据库的一条记录处理成以下三种情况,
 * <b>默认都是处理结果集中的第一条记录</b>
 * <ul>
 *     <li>数组</li>
 *     <li>Map</li>
 *     <li>Bean</li>
 * </ul>
 * 假定数据库是如下情况:
 * <table >
 *     <tr style="background-color:blue"><td>id</td><td>name</td><td>salary</td></tr>
 *     <tr><td>5</td><td>张三</td><td>5000.50</td></tr>
 *     <tr><td>15</td><td>李四</td><td>7000</td></tr>
 *     <tr><td>35</td><td>王五</td><td>15000</td></tr>
 * </table>
 * <h3>处理成数组</h3>
 * [5,张三,5000]
 * <h3>处理成map</h3>
 * {id:5},{name:张三},{salary:5000}
 * <h3>处理成bean</h3>
 * 默认把查询的列名与bean的同名属性进行映射
 * <pre style="code">
 * public class Emp{
 *     private Integer id;
 *     private String name;
 *     private double salary;
 *     //省略getter，setter
 * }
 * </pre>
 */
public interface RowProcessor {

    RowProcessor DEFAULT_ROWPROCESSOR = new DefaultRowProcessor();

    Object[] toArray(ResultSet rs) throws SQLException;

    Map<String, Object> toMap(ResultSet rs) throws SQLException;

    <T> T toBean(ResultSet rs, Class<?> beanClz) throws SQLException;

    <T> T toScalar(ResultSet rs, String columnNameS) throws SQLException;
}
